package com.letao.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.letao.server.dto.Result;
import com.letao.server.dto.SeckillOrderDetailDTO;
import com.letao.server.entity.OrderDetailSeckill;
import com.letao.server.entity.SeckillInfo;
import com.letao.server.mapper.OrderDetailSeckillMapper;
import com.letao.server.mapper.SeckillInfoMapper;
import com.letao.server.service.IOrderDetailSeckillService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderDetailSeckillServiceImpl extends ServiceImpl<OrderDetailSeckillMapper, OrderDetailSeckill> implements IOrderDetailSeckillService {

    @Resource
    private SeckillInfoMapper seckillInfoMapper;


    @Override
    public Result getInfo(Long id, Long userId) {
        OrderDetailSeckill info = query().eq("order_id", id).one();
        SeckillOrderDetailDTO seckillOrderDetailDTO = BeanUtil.copyProperties(info, SeckillOrderDetailDTO.class);
        log.debug("11111{}", seckillOrderDetailDTO);
        SeckillInfo seckillInfo = seckillInfoMapper.selectById(seckillOrderDetailDTO.getSeckillId());
        seckillOrderDetailDTO.setName(seckillInfo.getName());
        seckillOrderDetailDTO.setImage(seckillInfo.getSeckillImage());

        return Result.success(seckillOrderDetailDTO);
    }
}
